package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.OtherStudentDao;
import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
    //OtherStudentDao studentDao=new OtherStudentDao();
    StudentDao studentDao = new StudentDao();

    public boolean addStudent(Student stu) {
        //StudentDao studentDao=new StudentDao();
        return studentDao.addStudent(stu);
    }

    public boolean isExists(String id) {
        // StudentDao studentDao=new StudentDao();
        Student[] stu = studentDao.findAllStudent();
        //假设id在数组中不存在
        boolean flag = false;
        for (int i = 0; i < stu.length; i++) {
            Student student = stu[i];
            if (student != null && student.getId().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Student[] finAllStudent() {
        Student[] allStudent = studentDao.findAllStudent();
        boolean flag = false;
      for (int i = 0; i < allStudent.length; i++) {
            if (allStudent[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return allStudent;
        } else {
            return null;
        }
    }

    public void deleteStudent(String sid) {
        studentDao.deleteStudent(sid);//直接用类名调用的方法。
        //studentDao.deleteStudent(sid);
    }


    public void updataStudent(Student student, String sid) {
        studentDao.updataStudent(student,sid);
    }

}

